
object Arrays {
	def main() : Unit = { {
		if (new Array2().test() == 190) println("PASS: array test");
		else println("FAIL: array test");
		if (new Obj().set(6).b().a().a().b().a().b().get() == 7) println("PASS: array_objpass");
		else println("FAIL: array_objpass");
	} }
}

/* test 2 */


class Obj {
	var v:Int;
	def get():Int = { return v; }
	def set(i:Int):Obj = { v=i; return this; }
	def a():Obj = {
		v = v * 3;
		return this;
	}
	def b():Obj = {
		v = v-5;
		return this;
	}
}



/* array test */

class Array1 {
	var a:Int[];
	def init () : Bool = {
		var r:Bool;
		var i:Int;
		a = new Int[20];
		r = true;
		i = 0;
		while (i < a.length) {
			r = r && this.set(i);
			i = i + 1;
		}
		return r;
	}
	def set(i:Int) : Bool = {
		var r:Bool;
		r = false;
		r = (i < a.length);
		if (r) {
			a[i] = 0;
		}
		return r;
	}
	def sum() : Int = {
		var i:Int;
		var s:Int;
		s = 0;
		i = 0;
		while (i<a.length) {
			s = s + a[i];
			i = i + 1;
		}
		return s;
	}
}
class Array2 extends Array1 {
	def test():Int = {
		var r:Bool;
		var i:Int;
		r = this.init();
		i = 0;
		while (i<20) {
			a[i] = i;
			i = i + 1;
		}
		return this.sum();
	}
}
